﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace LuKou.Web.View
{
    public class LuKouViewEngine : WebFormViewEngine
    {
        public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
        {
            String names = controllerContext.Controller.GetType().Namespace;

            if (names.StartsWith("LuKou.Web.Controllers.Manage"))
            {
                MasterLocationFormats = new[] {
                    "~/Themes/Manage/{1}/{0}.master",
                    "~/Themes/Manage/Shared/{0}.master",
                    "~/Themes/Shared/{0}.master"
                };

                ViewLocationFormats = new[] {
                    "~/Themes/Manage/{1}/{0}.aspx",
                    "~/Themes/Manage/{1}/{0}.ascx",
                    "~/Themes/Manage/{0}.aspx",
                    "~/Themes/Manage/{0}.ascx",
                    "~/Themes/Manage/Shared/{0}.aspx",
                    "~/Themes/Manage/Shared/{0}.ascx",
                    "~/Themes/Shared/{0}.aspx",
                    "~/Themes/Shared/{0}.ascx",
                };

                PartialViewLocationFormats = ViewLocationFormats;
            }
            else
            {
                MasterLocationFormats = new[] {
                    "~/Themes/Web/{1}/{0}.master",
                    "~/Themes/Web/Shared/{0}.master",
                    "~/Themes/Shared/{0}.master"
                };

                ViewLocationFormats = new[] {
                    "~/Themes/Web/{1}/{0}.aspx",
                    "~/Themes/Web/{1}/{0}.ascx",
                    "~/Themes/Web/{0}.aspx",
                    "~/Themes/Web/{0}.ascx",
                    "~/Themes/Web/Shared/{0}.aspx",
                    "~/Themes/Web/Shared/{0}.ascx",
                    "~/Themes/Shared/{0}.aspx",
                    "~/Themes/Shared/{0}.ascx",
                };

                PartialViewLocationFormats = ViewLocationFormats;
            }
            return base.FindView(controllerContext, viewName, masterName, useCache);
        }
    }
}
